extends HoldMagic

@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var hit_area: Area2D = $HitArea


func use():
	AudioManager.play_sound("sfx_ocean")
	
	var config = item_data.item_config as MagicStaffConfig
	animation_player.play("attack")
	await get_tree().create_timer(config.use_time).timeout
	
	attack()
	
	await get_tree().create_timer(0.3).timeout
	animation_player.play("sword_recover")
	AudioManager.play_sound("sfx_ocean")


func attack():
	var areas = hit_area.get_overlapping_areas()
	if areas.size() <= 0: return
	
	var config = item_data.item_config as MagicStaffConfig
	var player = holder as Player
	
	for area in areas:
		var source = area.source 
		if source.has_method("add_buff"):
			var buff = source.add_buff("buff_sakura_attack", holder) as BuffSakuraAttack
			buff.attack = config.attack + player.player_data.get_attack()
			buff.critical_rate = config.critical_rate
			buff.critical_bonus = config.critical_bonus
			buff.knockback = config.knockback
			buff.start_buff()
	
	
	
	
	
